package com.hs.controller;

import com.hs.config.R;
import com.hs.entity.ClassLesson;
import com.hs.entity.User;
import com.hs.service.ClassLessonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("classLesson")
public class ClassLessonController {
    @Autowired
    ClassLessonService classLessonService;


    @RequestMapping(value = "insert",produces="application/json;charset=utf-8")
    @ResponseBody
    public R insert(HttpSession session, ClassLesson record, Model model) {
        if (record == null) {
            return R.FAILURE("请填写班级信息", null);
        }
        if (record.getClassId() == null || record.getLessonId() == null) {
            model.addAttribute("msg", "请填写关联信息");
            return R.FAILURE("请填写关联信息", null);
        }
        User user = (User) session.getAttribute("user");
        record.setCreateUser(user.getId());
        int i = classLessonService.insertSelective(record);
        if (i > 0) {
            return R.SUCCESS("", i);
        }
        return R.FAILURE("", 0);
    }




}
